package o;

import com.huawei.appgallery.forum.base.card.bean.Section;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import o.bun.h;

public class buw extends chz {
    public buw(long j, cie o_cie, int i, List<CardBean> list) {
        super(j, o_cie, i, list);
    }

    public void ˊ(Section section) {
        if (section != null) {
            buu ॱ;
            List list;
            buu ˋॱ = ˋॱ();
            if (ˋॱ == null) {
                ॱ = ॱ();
            } else {
                ॱ = ˋॱ;
            }
            List ˊ = ॱ.ˊ();
            if (ˊ == null) {
                ˊ = new ArrayList();
                ॱ.ˋ(ˊ);
                list = ˊ;
            } else {
                list = ˊ;
            }
            Iterator it = list.iterator();
            while (it.hasNext()) {
                Section section2 = (Section) it.next();
                if (section2 != null && section2.ˊ() == section.ˊ()) {
                    it.remove();
                    bqx.ˋ("FollowSectionCardChunk", "update section followed  removed");
                }
            }
            if (section.ʽ()) {
                list.add(0, section);
                if (list.size() > 8) {
                    ॱ.ˋ(list.subList(0, 8));
                }
            } else if (list.size() == 0 && this.ˎ != null) {
                this.ˎ.clear();
            }
        }
    }

    private buu ॱ() {
        buu o_buu = new buu();
        o_buu.ˋ(bqy.ˋ().ˏ().getResources().getString(h.ˏ));
        o_buu.ॱ("forum|following_forums");
        if (this.ˎ != null) {
            this.ˎ.clear();
            this.ˎ.add(o_buu);
        }
        return o_buu;
    }

    private buu ˋॱ() {
        if (this.ˎ != null && this.ˎ.size() > 0) {
            CardBean cardBean = (CardBean) this.ˎ.get(0);
            if (cardBean instanceof buu) {
                return (buu) cardBean;
            }
        }
        return null;
    }
}
